/*
 * =====================================================================================
 *
 *       Filename:  helloworld.c
 *
 *    Description:  第一个linux module编写
 *
 *        Version:  1.0
 *        Created:  2018年08月28日 17时05分35秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  NYB (), niuyabeng@126.com
 *   Organization:  
 *
 * =====================================================================================
 */

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/moduleparam.h>
#define ZONE_MAX 8
static char *inbound[ZONE_MAX] = {0};
static char *outbound[ZONE_MAX] = {0};
static int len_inbound = 0;
static int len_outbound = 0;
module_param_array(inbound, charp, &len_inbound, S_IRUGO);
module_param_array(outbound, charp, &len_outbound, S_IRUGO);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("NYB");


static int helloworld_export_symbol(void)
{
    return 1;
}

static void print_zone_inbound_outbound(void)
{
    int i;
    for(i = 0; i < len_inbound; i++) {
        if(inbound[i]) {
            printk(KERN_EMERG"inbound %d:%s\n", i, inbound[i]);
        }
    }
    for(i = 0; i < len_outbound; i++) {
        if(outbound[i]) {
            printk(KERN_EMERG"outbound %d:%s\n", i, outbound[i]);
        }
    }
}

static int helloworld_init(void)
{
    printk(KERN_EMERG"%s: start\n", __func__);
    if(len_inbound <= 0 || len_outbound <=0) {
        printk(KERN_EMERG"len_inbound <= 0\n");
        return -1;
    }
    print_zone_inbound_outbound();
    return 0; 
}

static void helloworld_exit(void)
{
    printk(KERN_EMERG"%s: start\n", __func__);
}
 
module_init(helloworld_init);
module_exit(helloworld_exit);

